﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Cafe.DataObjectTransfer;
using Cafe.BusinessLogic;

namespace Cafe.Presentation
{
    public partial class EditProductForm : DevExpress.XtraEditors.XtraForm
    {
        private CafeManagementService _cafeService=Program.cafeService;
        public Boolean isEdit = false;
        public String ProductName
        {
            get
            {
                return txtProductName.Text;
            }
            set
            {
                txtProductName.Text = value;
            }
        }
        public String Description
        {
            get
            {
                return txtDescription.Text;
            }
            set
            {
                txtDescription.Text = value;
            }
        }
        public int UnitID
        {
            get
            {
                return Convert.ToInt32(cbUnit.SelectedValue);
            }
            set
            {
                cbUnit.SelectedValue = value;
            }
        }
        public int  CatalogueID
        {
            get
            {
                return Convert.ToInt32(cbCatalogue.SelectedItem);
            }
            set
            {
                cbCatalogue.SelectedValue = value;
            }
        }
        public decimal Price
        {
            get
            {
                return Convert.ToInt64(txtPrice.Text);
            }
            set
            {
                txtPrice.Text = value.ToString();
            }
        }
        public decimal PromoPrice
        {
            get
            {
                return Convert.ToInt64(txtPromoPrice.Text);
            }
            set
            {
                txtPromoPrice.Text = value.ToString();
            }

        }
        public DateTime DateStart
        {
            get
            {
                return dtpDateStart.Value;
            }
            set
            {
                if (value < dtpDateStart.Value) dtpDateStart.Value = dtpDateStart.MinDate;
                else
                    dtpDateStart.Value = value;
            }

        }
        public DateTime DateEnd
        {
            get
            {
                return dtpDateEnd.Value;
            }
            set
            {
                if (value < dtpDateEnd.Value) dtpDateEnd.Value = dtpDateEnd.MinDate;
                else
                    dtpDateEnd.Value = value;
            }
        }
        public EditProductForm()
        {
            InitializeComponent();
            cbUnit.DataSource = _cafeService.GetUnits();
            cbCatalogue.DataSource=_cafeService.GetCatalogues();
            cbUnit.DisplayMember = "UnitName";
            cbUnit.ValueMember = "UnitID";
            cbCatalogue.DisplayMember = "CatalogueName";
            cbCatalogue.ValueMember = "CatalogueID";
        }

        private void EditProductForm_Load(object sender, EventArgs e)
        {
            if (isEdit) this.Text = "Cập nhật thông tin đồ uống";
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
    }
}